"""
Created on 27-Oct-2009

@author: dexen
"""


import conds
from individual import Individual
from libs import input_reading
from const import POP_SIZE, FEED_SIZE, MAX_BIRTH
from slave_tasks.dev import DevTask
from slave_tasks.eval import EvalTask
from slave_tasks.feedback import FeedbackTask

import dexen



class MasterTask(dexen.BaseMasterTask):
    def __init__(self, master_env):
        assert isinstance(master_env, dexen.MasterEnv)
        master_env.start_task(DevTask, "Development", FEED_SIZE/2, conds.dev_cond)
        master_env.start_task(EvalTask, "Evaluation", FEED_SIZE/2, conds.eval_cond)
        master_env.start_task(FeedbackTask, "Feedback", FEED_SIZE, conds.feedback_cond)
        boxes = input_reading.read_input()
        for _ in range(POP_SIZE):
            ind = Individual(len(boxes))
            master_env.set_ind(ind)
    
    def __execute__(self, master_env):
        assert isinstance(master_env, dexen.MasterEnv)
        if master_env.num_inds() == MAX_BIRTH:
            master_env.stop_master()

    
